package com.swy.shopgroup.service.impl;


import com.swy.shopgroup.ResultUtils;
import com.swy.shopgroup.dao.*;
import com.swy.shopgroup.entity.*;
import com.swy.shopgroup.service.GoodsService;
import com.swy.shopgroup.service.OutPageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Service
public class PageOutServiceImpl implements OutPageService {

    @Resource
    OutPageMapper outPageMapper;

    @Resource
    PageAcceptMapper acceptMapper;

    @Resource
    ShopUserMapper userMapper;

    @Resource
    ShopInfoMapper infoMapper;

    @Override
    public Result selectOutPageByShop(Long id) {
        return ResultUtils.success("查询成功", outPageMapper.selectOutPageByShop(id));
    }

    @Override
    public Result selectAll() {
        return ResultUtils.success("查询成功", outPageMapper.selectAll());
    }

    @Override
    public Result insertOutPage(OutPage outPage) {
        return ResultUtils.success("查询成功", outPageMapper.insert(outPage));
    }

    @Override
    public Result selectAcceptByShop(Long id) {
        List<PageAccept> list = acceptMapper.selectByShop(id);
        List<Accepts> listResult = new ArrayList<>();
        ShopInfo shopInfo = infoMapper.selectByPrimaryKey(id);
        for (PageAccept pageAccept : list) {
            Accepts accepts = new Accepts();
            accepts.setShopInfo(shopInfo);
            accepts.setShopUser(userMapper.selectByPrimaryKey(pageAccept.getUserId()));
            accepts.setOutPage(outPageMapper.selectByPrimaryKey(pageAccept.getPageId()));
            listResult.add(accepts);
        }
        return ResultUtils.success("查询成功", listResult);
    }

    @Override
    public Result selectAcceptByUser(Long id) {
        List<PageAccept> list = acceptMapper.selectByUser(id);
        List<Accepts> listResult = new ArrayList<>();
        ShopUser shopUser = userMapper.selectByPrimaryKey(id);
        for (PageAccept pageAccept : list) {
            Accepts accepts = new Accepts();
            accepts.setShopUser(shopUser);
            accepts.setShopInfo(infoMapper.selectByPrimaryKey(pageAccept.getShopId()));
            accepts.setOutPage(outPageMapper.selectByPrimaryKey(pageAccept.getPageId()));
            listResult.add(accepts);
        }
        return ResultUtils.success("查询成功", listResult);
    }

    @Override
    public Result insertAccept(PageAccept pageAccept) {
        return ResultUtils.success("应聘请求发送成功", acceptMapper.insert(pageAccept));
    }
}
